package com.bum.sock.poll.bootstrap;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.asao.baseware.core.DefaultApplication;

public class SockPollBootstrap implements ServletContextListener {
	Log	log	= LogFactory.getLog(getClass());
	private DefaultApplication	app;

	@SuppressWarnings("rawtypes")
	void startApplication() {
		log.info("_/_/_/_/_/_/_/_/_/_/ Starting Game Socket Application... _/_/_/_/_/_/_/_/_/_/");

		try {
			app = new DefaultApplication("config/application.cfg.xml");
			app.setPropertiesLocations(new String[] {
					"/config/application.properties"
			});
			app.start();

			log.info("_/_/_/_/_/_/_/_/_/_/ Game Socket Application started! _/_/_/_/_/_/_/_/_/_/");
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}

	void stopApplication() {
		log.info("_/_/_/_/_/_/_/_/_/_/ Stopping Game Socket Application... _/_/_/_/_/_/_/_/_/_/");

		DefaultApplication.theApplication().stop();

		log.info("_/_/_/_/_/_/_/_/_/_/ Game Socket Application stopped! _/_/_/_/_/_/_/_/_/_/");
	}

	public void contextInitialized(ServletContextEvent arg0) {
		startApplication();
	}

	public void contextDestroyed(ServletContextEvent arg0) {
		stopApplication();
	}

}
